package br.com.gkarian.mydesk.dao.financeiro;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import br.com.caelum.vraptor.ioc.Component;
import br.com.gkarian.mydesk.dao.financeiro.interfaces.TransacaoDAO;
import br.com.gkarian.mydesk.model.financeiro.Transacao;

@Component
public class TransacaoDAOImpl implements TransacaoDAO {

	private static final Logger LOG = Logger.getLogger(TransacaoDAOImpl.class);
	
	private SessionFactory sf;
	
	public TransacaoDAOImpl(SessionFactory sf) {
		this.sf = sf;
	}
	
	private Session getSession() {
		return this.sf.getCurrentSession();
	}

	@Override
	public void salvar(Transacao transacao) throws Exception {
		getSession().save(transacao);
	}

	@Override
	public void atualizar(Transacao transacao) throws Exception {
		getSession().merge(transacao);
	}

	@Override
	public void remover(Transacao transacao) throws Exception {
		getSession().delete(transacao);
	}
	
	@Override
	public Transacao carregar(Integer id) throws Exception {
		return (Transacao) getSession().load(Transacao.class, id);
	}
	
	@SuppressWarnings("unchecked")
	public List<Transacao> listaTudo() throws Exception {
	    return getSession().createCriteria(Transacao.class).list();
    }
	



}
